class FileListPlugin {
  constructor(options = {}) {
    this.filename = options.filename || 'file-list.md';
  }

  apply(compiler) {
    compiler.hooks.emit.tapAsync('FileListPlugin', (compilation, callback) => {
      let fileList = '## 打包文件清单\n\n';
      for (const filename in compilation.assets) {
        fileList += `- ${filename}\n`;
      }
      compilation.assets[this.filename] = {
        source: () => fileList,
        size: () => fileList.length
      };
      callback();
    });
  }
}

module.exports = FileListPlugin;
